home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / viewwrld / viewwrld.lha / viewworld / lgd / sunview / dev.c next >
Encoding:
C/C++ Source or Header  |  1989-09-21  |  5.3 KB  |  215 lines

  1. /* $Id: dev.c,v 1.7 89/09/20 17:59:53 mbp Exp $
  2.  *
  3.  * dev.c: device commands for SunView
  4.  */
  5.  
  6. /************************************************************************
  7.  *        Copyright (C) 1989 by Mark B. Phillips                  *
  8.  *                                     *
  9.  * Permission to use, copy, modify, and distribute this software and    *
  10.  * its documentation for any purpose and without fee is hereby granted, *
  11.  * provided that the above copyright notice appear in all copies and    *
  12.  * that both that copyright notice and this permission notice appear in *
  13.  * supporting documentation, and that the name of Mark B. Phillips or   *
  14.  * the University of Maryland not be used in advertising or publicity   *
  15.  * pertaining to distribution of the software without specific, written *
  16.  * prior permission.  This software is provided "as is" without express *
  17.  * or implied warranty.                                                 *
  18.  ************************************************************************/
  19.  
  20. /* NOTE: this file assumes that the preprocessor macro HELPFILE will
  21.  * be defined on the command line with the -D option.  It should be
  22.  * the complete pathname of the file "sunview.help".
  23.  *
  24.  * It also assumes that GR_HEADER is the quoted pathname of the file
  25.  * gr.h.
  26.  */
  27.  
  28. #include <suntool/sunview.h>
  29. #include <stdio.h>
  30. #include <math.h>
  31. #include "../lgd.h"
  32. #include "dev.h"
  33. #include GR_HEADER
  34.  
  35. /************************************************************************
  36.  *             PRIVATE DEFINITIONS                *
  37.  ************************************************************************/
  38.  
  39. #define NO  0
  40. #define YES 1
  41.  
  42. lgd_Menu *current_menu=NULL;
  43. static int argc=0;
  44. static char **argv=NULL;
  45.  
  46. /* Icon definition: */
  47. static short icon_image[] = {
  48. #include "lgd.icon"
  49. };
  50. DEFINE_ICON_FROM_IMAGE(lgd_icon, icon_image);
  51.  
  52. /************************************************************************
  53.  *              PUBLIC PROCEDURES                *
  54.  ************************************************************************/
  55.  
  56. /*-----------------------------------------------------------------------
  57.  * Function:    lgd_set_suntools_args
  58.  * Description:    specifiy generic Suntools window argument list
  59.  * Args  IN:    argc,argv: the window args from the program's command
  60.  *          line
  61.  * Notes:    The use of this procedure is entirely optional.
  62.  */
  63. lgd_set_suntools_args(main_argc, main_argv)
  64.      int main_argc;
  65.      char **main_argv;
  66. {
  67.   argc = main_argc;
  68.   argv = main_argv;
  69. }
  70.  
  71. /*--------------------------------------------------------------*/
  72. dev_initialize()
  73. {
  74.   static int initialized=NO;
  75.   extern int gr_redraw();
  76.   char fname[256];
  77.  
  78.   if (!initialized) {     /* If we've not yet initialized, do so */
  79.     gr_initialize(argc, argv);
  80.     gr_set_frame_label("LGD");
  81.     gr_set_frame_icon(&lgd_icon);
  82.     gr_print_button(1, gr_redraw, "LGD");
  83.     construct_help_file_name(fname);
  84.     gr_set_help_file(fname);
  85.     initialized=YES;
  86.   }
  87.   else {         /* If we've already initialized, just */
  88.     gr_erase();            /* erase the screen */
  89.   }
  90. }
  91.  
  92. /*--------------------------------------------------------------*/
  93. dev_set_menu( menu )
  94. lgd_Menu *menu;
  95. {
  96.   current_menu = menu;
  97.   gr_set_menu( menu );
  98. }
  99.  
  100. /*--------------------------------------------------------------*/
  101. dev_inquire_menu( menu )
  102. lgd_Menu **menu;
  103. {
  104.   *menu = current_menu;
  105. }
  106.  
  107. /*--------------------------------------------------------------*/
  108. dev_main_loop()
  109. {
  110.   gr_main_loop();
  111. }
  112.  
  113. /*--------------------------------------------------------------*/
  114. dev_end_loop()
  115. {
  116.   gr_done();
  117. }
  118.  
  119. /*--------------------------------------------------------------*/
  120. dev_get_string(s)
  121. char *s;
  122. {
  123.   gr_get_string(s);
  124. }
  125.  
  126. /*--------------------------------------------------------------*/
  127. dev_put_string(s)
  128. char *s;
  129. {
  130.   gr_message( s, 1 );
  131. }
  132.  
  133. /*--------------------------------------------------------------*/
  134. dev_confirm(s)
  135. char *s;
  136. {
  137.   return(gr_user_confirm(s));
  138. }
  139.  
  140. /*--------------------------------------------------------------*/
  141. dev_get_point(v)
  142. double v[];
  143. {
  144.   char buf[40];
  145.   gr_message("Enter x coordinate of point:",2);
  146.   gr_get_string(buf);
  147.   v[0] = atof(buf);
  148.   gr_message("Enter y coordinate of point:",2);
  149.   gr_get_string(buf);
  150.   v[1] = atof(buf);
  151.   gr_message("Enter z coordinate of point:",2);
  152.   gr_get_string(buf);
  153.   v[2] = atof(buf);
  154.   gr_message("",2);
  155. }
  156.  
  157. /*--------------------------------------------------------------*/
  158. dev_update_display()
  159. {
  160.   lgd_View3 view;
  161.  
  162.   lgd_inquire_view( &view );
  163.   gr_set_eye_display( view.eye );
  164.   gr_set_focus_display( view.focus );
  165.   gr_set_up_display( view.up );
  166.   gr_set_view_plane_window_display( view.u1, view.u2, view.v1, view.v2 );
  167. }
  168.  
  169. /*--------------------------------------------------------------*/
  170. dev_get_ndc_point(x, y)
  171. double *x,*y;
  172. {
  173.   int X,Y;
  174.  
  175.   gr_Button button;
  176.  
  177.   gr_button_message( "pick point", "", "", "", "", "", "" );
  178.   gr_get_canvas_xy(&X, &Y, &button, GR_LEFT);
  179.   *x = X;
  180.   *y = Y;
  181.   gr_button_message_clear();
  182. }
  183.  
  184. dev_signal(sig, func)
  185. int sig, (*func)();
  186. {
  187.   gr_signal(sig, func);
  188. }
  189.  
  190. dev_set_input_func(func, fd)
  191. int (*func)(), fd;
  192. {
  193.   gr_set_input_func(func, fd);
  194. }
  195.  
  196. static
  197.   construct_help_file_name(fname)
  198. char *fname;
  199. {
  200.   extern char *getenv();
  201.   char *lgd_lib;
  202.  
  203.   /* First look in LGD_LIB */
  204.   lgd_lib = getenv("LGD_LIB");
  205.   if (lgd_lib != NULL) {
  206.     sprintf(fname,"%s%s%s",
  207.         lgd_lib, (lgd_lib[strlen(lgd_lib)-1]=='/') ? "" : "/",
  208.         "sunview.help");
  209.     if (GR_file_openable(fname, "r")) return;
  210.   }
  211.  
  212.   /* If not there, then use default */
  213.   strcpy(fname, HELPFILE);
  214. }
  215.